package com.ExcelServer.mapper;

import com.ExcelServer.pojo.entity.PerformanceTrends;
import com.ExcelServer.pojo.query.TableNameQuery;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
* @author admin
* @description 针对表【performance_trends(业绩的动态表格控制器)】的数据库操作Mapper
* @createDate 2024-03-23 11:45:48
* @Entity com.ExcelServer.pojo.entity.PerformanceTrends
*/
@Mapper
public interface PerformanceTrendsMapper extends BaseMapper<PerformanceTrends> {

    Integer getMaxId();

    @Update("CREATE TABLE IF NOT EXISTS ${tableName} ("
            + "id INT AUTO_INCREMENT PRIMARY KEY, "
            + "${columnDefinition})")
    void createTable(@Param("tableName") String mTableName, @Param("columnDefinition") String columnDefinition);

    @Select("SELECT *  FROM ${tableName} where ${condition}")
    List<Map<String, Object>> getTableDetails(@Param("tableName")String mTableName, @Param("condition") String condition);

    @Update("UPDATE ${tableName} set  ${line} where ${condition}")
    boolean updateDetails(@Param("tableName")String tableName, @Param("line")String line, @Param("condition")String condition);

    @Delete("drop table IF EXISTS ${tableName}")
    boolean deletePerformanceById(@Param("tableName")String tableName);

    @Delete("DELETE FROM ${tableName} where ${condition}")
    boolean deletePerformanceDetailsById(@Param("tableName")String tableName, @Param("condition")String condition);

    @Insert("INSERT  INTO ${tableName} (${columns}) values (${values})")
    void addDetails(@Param("tableName")String mTableName, @Param("columns") StringBuilder columns, @Param("values")StringBuilder values);

    @Select("SELECT *  FROM ${tableName} where ${condition}")
    Page<Map<String, Object>> getTableDetailsByPage(Page<Map<String, Object>> page, @Param("tableName")String mTableName, @Param("condition") String condition);

    List<PerformanceTrends> getTable(@Param("qu") TableNameQuery tableNameQuery);
    @Select("SELECT * FROM ${tableName} where teacher_id LIKE CONCAT('%', #{teacherId}, '%')  ")
    List<Map<String, Object>> getTableNamesByTeacherIdWithDisagree(@Param("tableName") String tableName, @Param("teacherId") String teacherId);
    @Select("SELECT * FROM ${tableName} where teacher_id LIKE CONCAT('%', #{teacherId}, '%') AND is_audit = 'agree' ")
    List<Map<String, Object>> getTableNamesByTeacherId(@Param("tableName") String tableName, @Param("teacherId") String teacherId);
    @Select("SELECT DISTINCT teacher_id FROM ${tableName} where is_audit = 'agree' ")
    List<String> getAllTeacherId(@Param("tableName") String tableName);

    @Select("SELECT COUNT(*) FROM ${tableName} where is_audit = 'agree' ")
    Long getPerformanceCount(@Param("tableName")String tableName);
}




